<?php

namespace plugin\agent\app\model;

use app\model\user\User;
use think\Model;

/**
 * t_agent_withdrawal 提现申请
 * @property integer $id ID(主键)
 * @property integer $user_id 申请人id
 * @property string $type 提现方式
 * @property string $card_no 卡号
 * @property string $name 持卡人名
 * @property string $bank 所属银行
 * @property string $apply_amount 提现金额
 * @property string $account 微信或支付宝账号
 * @property string $receive_qrcode 收款码
 * @property integer $status 状态 1:申请中 2:通过 3:拒绝
 * @property string $desc 打款备注
 * @property string $create_time 创建时间
 * @property string $update_time 更新时间
 */
class AgentWithdrawal extends Model
{
    /**
     * The connection name for the model.
     *
     * @var string|null
     */
    protected $connection = 'mysql';

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 't_agent_withdrawal';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $pk = 'id';

    //状态 1:申请中 2:通过 3:拒绝
    const STATUS_WAIT = 1;
    const STATUS_AGREE = 2;
    const STATUS_REFUSE = 3;

    const STATUS_TEXT_MAP = [
        self::STATUS_WAIT => "申请中",
        self::STATUS_AGREE => "通过",
        self::STATUS_REFUSE => "拒绝",
    ];
    protected $append = [
        'status_text'
    ];

    public function getStatusTextAttr($value, $data)
    {
        return self::STATUS_TEXT_MAP[$data['status']] ?? "";
    }

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }
}
